﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    partial class ManagerClient : Form
    {
        private Client client;

        public ManagerClient(Client c)
        {
            client = c;
            InitializeComponent();
            labelClient.Text = "Client: " + c.getNume()+ " " + c.getPrenume() + " - " + c.getVarsta() + " ani";
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            this.Close();
            Form f = ManagerClienti.getManagerClienti();
            f.Close();
        }

        private void clear()
        {
            textNume.ResetText();
            textTip.ResetText();
            textDotari.ResetText();
            textDimensiuni.ResetText();
            textMotorizare.ResetText();
            textCuloare.ResetText();
            textTransmisie.ResetText();
            richTextBox1.Text = "";
        }

        private void buttonListare_Click(object sender, EventArgs e)
        {
            clear();

            richTextBox1.Text = client.printCars();
        }

        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.Close();
            Form f = ManagerClienti.getManagerClienti();
            f.Show();
        }

        private void buttonAdauga_Click(object sender, EventArgs e)
        {
            try
            {
                string nume = textNume.Text,
                        tip = textTip.Text,
                        dotari = textDotari.Text,
                        dim = textDimensiuni.Text,
                        mot = textMotorizare.Text,
                        culoare = textCuloare.Text,
                        trans = textTransmisie.Text;

                int test = client.addMasina(culoare, trans, dim, mot, dotari, nume, tip);
                if ( test == -1)
                {
                    MessageBox.Show("Tipul trebuie sa fie: sedan, mini sau coupe!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    textTip.Text = "";
                }
                else
                    if (test == 1)
                    {
                        MessageBox.Show("Masina exista! Introduceti alt nume! ", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        clear();
                    }
                    else
                    {
                        clear();
                        MessageBox.Show("Masina adaugata!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    }
            }
            catch
            {
                MessageBox.Show("Date invalide!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            clear();
        }

        private void buttonSterge_Click(object sender, EventArgs e)
        {
            try
            {
                string nume = textNume.Text,
                        tip = textTip.Text,
                        dotari = textDotari.Text,
                        dim = textDimensiuni.Text,
                        mot = textMotorizare.Text,
                        culoare = textCuloare.Text,
                        trans = textTransmisie.Text;

                client.rmMasina(culoare, trans, dim, mot, dotari, nume);
                MessageBox.Show("Masina eliminata!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            catch
            {
                MessageBox.Show("Date invalide!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            clear();
        }
    }
}
